<?php
class courseModel extends appModel{
    
    protected function init(){
        
    } 

    public function getcoursefields(){       
        $data = array();
        
        $start = isset($_GET['start']) ? $_GET['start'] : 0;
        $limit = isset($_GET['limit']) ? $_GET['limit'] : 10;

        $query = "SELECT * FROM `course_fields` ORDER BY `name` LIMIT {$start},{$limit}";

        $result = $this->db->query($query);
        
        $nbrows = $this->db->fetchRow($this->db->query("SELECT COUNT(*) FROM `course_fields`"));
        $nbrows = $nbrows[0];
        while($row=$this->db->fetchAssoc($result)){
            $data[]=$row;
        }
// print_r($data);
        if(MyHelpers::isAjax()){
            // prepare the metadata
            $ret['metaData'] =   $this->makeMetaData($result);
            $ret['total']    =   $nbrows;
            $ret['data']     =   $this->Char2Utf8($data);
            $ret['success']  =   true;
            $ret['message']  =   true;
            return json_encode($ret);
        }


        return $data;       
    }
    public function getuniverName(){       
        $data = array();
        $start = isset($_GET['start']) ? $_GET['start'] : 0;
        $limit = isset($_GET['limit']) ? $_GET['limit'] : 10;
        $query = "SELECT * FROM `university` ORDER BY `name` LIMIT {$start},{$limit}";
        $result = $this->db->query($query);
        $nbrows = $this->db->fetchRow($this->db->query("SELECT COUNT(*) FROM `university`"));
        $nbrows = $nbrows[0];
        while($row=$this->db->fetchAssoc($result)){
            $data[]=$row;
        }

        return $data;       
    }
     public function courseName($id=null,$name,$country_id,$university_id,$create_date,$modified_date){
    if($id == null || $id == ""){
        $result = $this->db->query("INSERT INTO course_fields (name, country_id, university_id, create_date) VALUES ('$name', '$country_id', '$university_id', '$create_date')");
    } else{
        $result = $this->db->query("UPDATE `course_fields` SET name='$name', country_id='$country_id', university_id='$university_id',modified_date='$modified_date' WHERE `id`='$id'");
    }
        
    if($result !== false){
        $metaid = $this->db->insertId();
    } 
    return $metaid;
    }
}
?>